const moment = require("moment");


const TRADE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';

function timestampFormat(timestamp:number) {
    let r = moment(timestamp).format(TRADE_TIME_FORMAT);
    return r;
}
function formatTimeToTimestamp(format_timestamp:string) {
    return moment(format_timestamp, TRADE_TIME_FORMAT).valueOf();
}
function timestampAdd(timestamp:number, num:number, unit:string) {
    return moment(timestamp).add(num,unit).valueOf();
}
function formatDateAdd(format_timestamp:string, num:number, unit:string) {
    return moment(format_timestamp,TRADE_TIME_FORMAT).add(num,unit).valueOf();
}

function timestampSub(timestamp:number, num:number, unit:string) {
    return moment(timestamp).subtract(num,unit).valueOf();
}
function formatDateSub(format_timestamp:string, num:number, unit:string) {
    return moment(format_timestamp,TRADE_TIME_FORMAT).subtract(num,unit).valueOf();
}

export {
    timestampFormat, formatDateSub, timestampSub, formatDateAdd,formatTimeToTimestamp,timestampAdd, TRADE_TIME_FORMAT
}